#include<bits/stdc++.h>
using namespace std;
struct car{
    int l;
    int r;
    int d;
    int v;
    int a;
}a[100005];
int p[100005];
int ll[1000005],r[1000005];
bool cmp(car a,car b){
    return a.r<=b.r;
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while(t--){
        int n,m,l,v,ans1=0;
    cin >> n >> m >> l >> v;
    for(int i=1;i<=n;i++){
        cin >> a[i].d >> a[i].v >> a[i].a;
    }
    p[0]=-1;
    for(int i=1;i<=m;i++){
        cin >> p[i];
    }
    p[m+1]=l;
    for(int i=1;i<=m+1;i++){
        for(int j=p[i-1]+1;j<=p[i];j++)r[j]=i;
    }
    for(int i=0;i<=m;i++){
        for(int j=p[i];j<p[i+1];j++)ll[j]=i;
    }
    for(int i=1;i<=n;i++){
        if(a[i].a>0){
            if(a[i].v>v){
                a[i].l=r[a[i].d];
                a[i].r=m;
            }else{
                int p=ceil((v*v-a[i].v*a[i].v)/2.0/a[i].a)+a[i].d;
                if(p>l)a[i].l=m+1;
                else a[i].l=r[p];
                a[i].r=m;
            }
        }else if(a[i].a==0){
            if(a[i].v>v){
                a[i].l=r[a[i].d];
                a[i].r=m;
            }else{
                a[i].l=m+1;
                a[i].r=m;
            }
        }else{
            if(a[i].v>v){
                int p=floor((v*v-a[i].v*a[i].v)/2.0/a[i].a)+a[i].d;
                a[i].l=r[a[i].d];
                if(p>l)a[i].r=m;
                else a[i].r=ll[p];
            }else{
                a[i].l=m+1;
                a[i].r=m;
            }
        }
    }
    int la=-1,ans=0;
    for(int i=1;i<=n;i++){
        if(a[i].l>m||a[i].l>a[i].r){
            ans1++;
            continue;
        }
        q.push(make_pair(a[i].r,a[i].l));
    }
    while(!q.empty()){
        if(q.top().second>la){
            la=q.top().first;
            ans++;
        }
        q.pop();
    }
    cout << n-ans1 << ' ' << m-ans << '\n';
    }
    return 0;
}
